package game.objects;
import java.util.ArrayList;
import java.util.Vector;

import physics.Body;

import editors.objectedit.BoundingBox;
import editors.objectedit.LoadObject;
import game.Game;
import game.engine.TriggerArea;
import game.objects.npc.GODrone;
import game.waypoint.Path;
import game.waypoint.Waypoint;
import game.waypoint.WaypointSystem;
import graphics.objects.GraphicsObject;
import graphics.system.Color;
import tools.Help;
import tools.Point;
import tools.ReadFile;
public class GOMap extends GameObject {
	private String levelname;
	private transient WaypointSystem wsys;
	public GOMap(Game g, String levelname) {
		super(g, Point.ZERO);
		this.levelname = levelname;
		wsys = new WaypointSystem();
	}
	@Override
	public void handle() {
	}
	@Override
	public void initialize(Point pos) {
		if (levelname.equals("")) {
			return;
		}
		LoadObject.load(levelname, this);
		wsys.fromFileString(ReadFile.getContents("resources/models/" + levelname + ".wps"));
		//game.engine.setDrawWaypointSystem(wsys);
		for (int i = 0; i < numGraphicsObjects; i++) {
			String n = this.getName(this.getGraphicsObject(i));
			if (n.contains("spawn") && n.contains("drone")) {
				//game.addGameObject(new GODrone(game,getGraphicsObject(i).node.pos));
			}
		}
	}
	public Path getPathTo(Point from, Point to, boolean onFloor) {
		Vector<Point> pts = new Vector<Point>();
		Waypoint s = wsys.getNearest(from, onFloor);
		Waypoint e = wsys.getNearest(to, onFloor);
		if (s != null && e != null) {
			ArrayList<Waypoint> path = wsys.getPath(s, e, onFloor);
			if (path != null && path.size() > 0) {
				for (Waypoint w : path) {
					pts.add(w.pos);
				}
			}
		}
		return new Path(pts);
	}
	public WaypointSystem getWaypointSystem() {
		return wsys;
	}
}
